package com.violet.uaa.server.security.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

@Configuration
public class AccessTokenConfig {

    /**
     * 私钥
     */
    @Value("${rsa.private.key}")
    private String SIGN_KEY;

    @Bean
    public TokenStore tokenStore() {
        //使用JwtTokenStore生成令牌
        return new JwtTokenStore(jwtAccessTokenConverter());
    }

    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter() {
        JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
        //设置秘钥
        converter.setSigningKey(SIGN_KEY);
        return converter;
    }
}
